package com.hst.web.base.proxy;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.hst.core.Page;
import com.hst.core.ServiceContext;
import com.hst.core.dao.IORDao;
import com.hst.core.dao.ORQuery;
import com.hst.core.dao.ORQuery.Op;
import com.hst.core.meta.MetaData;
import com.hst.core.meta.proxies.DefaultDataProxy;
import com.hst.web.auth.po.User;
import com.hst.web.base.entity.TInvitationCode;
import com.hst.web.base.ui.InvitationCode;

public class InvitationCodeProxy extends DefaultDataProxy {

	@Autowired
	IORDao dao;

	@Override
	public Page<?> list(Map<String, ?> query, int pageIdx) {
		User user = (User) ServiceContext.getInstance().getUser();
		List<ORQuery> querys = parseQuery(query);
		querys.add(new ORQuery(Op.eq, "opCreate", user.getId()));
		querys.add(new ORQuery(Op.order, "createTime", "desc"));
		return dao.list(TInvitationCode.class, querys, pageIdx);
	}

	@Override
	public List<?> list(Map<String, ?> query) {
		User user = (User) ServiceContext.getInstance().getUser();
		List<ORQuery> querys = parseQuery(query);
		querys.add(new ORQuery(Op.eq, "opCreate", user.getId()));
		querys.add(new ORQuery(Op.order, "createTime", "desc"));
		return dao.list(TInvitationCode.class, querys);
	}

	@SuppressWarnings("unused")
	@Override
	public Object save(MetaData data) throws Exception {
		InvitationCode invitationCode = (InvitationCode) data;

		return super.save(data);
	}

}
